package study.java.thread06;

/**
* @Name: GetStudentRunnable
* @Description: 消费学生数据类
* @Author: 李超	lc_jack@foxmail.com
* @CreateDate: 2017-1-9 下午4:54:57 
* @Version: V1.0
 */
public class GetStudentRunnable implements Runnable {
	
	private Student student ;

	public GetStudentRunnable(Student student) {
		this.student = student;
	}

	@Override
	public void run() {
		while(true) {
			synchronized (student) {
				//判断是否有数据
				if(!student.getFlag()) {
					//如果没有数据，就等待，等待生产者生产数据
					try {
						student.wait() ;
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
				//消费数据
				System.err.println(student.getName() + ":" + student.getAge());
				//消费完数据之后，修改标记
				student.setFlag(false) ;
				//唤醒线程
				student.notify() ;
			}
		}
	}

}
